package com.ruoyi.hospital.controller.consultationInfo;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.consultationInfo.ConsultationPrice;
import com.ruoyi.hospital.service.consultationInfo.IConsultationPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 咨询费用Controller
 * 
 * @author wendao
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/hospital/consultationPrice")
public class ConsultationPriceController extends BaseController
{
    @Autowired
    private IConsultationPriceService consultationPriceService;

    /**
     * 查询咨询费用列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:consultationPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConsultationPrice consultationPrice)
    {
        startPage();
        List<ConsultationPrice> list = consultationPriceService.selectConsultationPriceList(consultationPrice);
        return getDataTable(list);
    }

    /**
     * 导出咨询费用列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:consultationPrice:export')")
    @Log(title = "咨询费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsultationPrice consultationPrice)
    {
        List<ConsultationPrice> list = consultationPriceService.selectConsultationPriceList(consultationPrice);
        ExcelUtil<ConsultationPrice> util = new ExcelUtil<ConsultationPrice>(ConsultationPrice.class);
        util.exportExcel(response, list, "咨询费用数据");
    }

    /**
     * 获取咨询费用详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:consultationPrice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(consultationPriceService.selectConsultationPriceById(id));
    }

    /**
     * 新增咨询费用
     */
    @PreAuthorize("@ss.hasPermi('hospital:consultationPrice:add')")
    @Log(title = "咨询费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsultationPrice consultationPrice)
    {
        //需要判断是否已经有此问诊类型了
        List<ConsultationPrice> list =  consultationPriceService.selectConsultationPriceList(consultationPrice);
        if(list.size()>0){  //表示已经添加
            return error("该问诊类型已存在，请确认");
        }
        return toAjax(consultationPriceService.insertConsultationPrice(consultationPrice));
    }

    /**
     * 修改咨询费用
     */
    @PreAuthorize("@ss.hasPermi('hospital:consultationPrice:edit')")
    @Log(title = "咨询费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsultationPrice consultationPrice)
    {
        //需要判断是否已经有此问诊类型了
        List<ConsultationPrice> list =  consultationPriceService.selectConsultationPriceList(consultationPrice);
        if(list.size()==1 && list.get(0).getId()!=consultationPrice.getId()){  //表示已经添加
            return error("该问诊类型已存在，请确认");
        }
        return toAjax(consultationPriceService.updateConsultationPrice(consultationPrice));
    }

    /**
     * 删除咨询费用
     */
    @PreAuthorize("@ss.hasPermi('hospital:consultationPrice:remove')")
    @Log(title = "咨询费用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(consultationPriceService.deleteConsultationPriceByIds(ids));
    }
}
